require('../lib/weui')
require('../less/mine.less')
require('../fonts/iconfont.css')


document.ready(function () {
    //加载导航守卫
    utils.navGuard()

    // 加载taps盒子
    utils.taps(2);

    // 获取id
    const userId = localStorage.getItem('userId')

    // 获取用户名
    const user_name = document.querySelector('.user_name')
    //获取图片

    const user_img = document.querySelector('.user_img')
    //个性签名
    const signature = document.querySelector('.signature span')

    // 获取运动时间
    const time = document.querySelector('.time')

    // 获取千卡
    const prana = document.querySelector('.prana')

    //获取运动数据按钮---去到图表页
    const box1=document.querySelector('.box1')

    //获取退出按钮
    const logout = document.querySelector('.logOut p')
    const iosDialog1 = document.querySelector('#iosDialog1')

    function getsport() {
        // 渲染
        axios.get(`${url}/users/mysportsBadge?userId=${userId}`)
        .then(function(res){
            res=res.data
            if (res.status === 0) {

                // 存储数据在本地  个人资料页面直接调用本地数据
                localStorage.setItem('userInfo', JSON.stringify(res.data.user))

                user_name.textContent = res.data.user.nickname;
                signature.textContent = res.data.user.sign || '这个人很懒还没有个性签名';
                // 判断图片
                if (res.data.user.imgurl) {
                    user_img.src = 'http://139.9.177.51:8099/' + res.data.user.imgurl
                }
                time.innerHTML = res.data.sports.times + `<span>分钟</span>`
                prana.innerHTML = res.data.sports.calorie + `<span>千卡</span>`
            }
        })
        .catch(function(error){
            console.log(error)
        })
        
    }

    getsport();

    //点击去修改
    user_img.addEventListener('click', function () {
        location.href = './personalInfo.html'
    })
    // 点击退出登录
    logout.addEventListener('click', function () {
        // weui.confirm('是否退出登录')
        // location.href = './login.html';
        iosDialog1.style.display = 'block'
    });

    const btnout = document.querySelector('.weui-dialog__btn_default');
    const btnok = document.querySelector('.weui-dialog__btn_primary');
    // 不退出
    btnout.addEventListener('click', function () {
        iosDialog1.style.display = 'none'
    });
    btnok.addEventListener('click',function(){
        localStorage.clear()
        location.href = './login.html'
    });

    // 点击跳转图表页
    box1.addEventListener('click',function(){
        location.href='./sportsData.html'
    })





})